package com.zhuzi.comsumer;

import cn.hutool.core.thread.ThreadUtil;
import com.zhuzi.utils.SysUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class JMSMessageReceiver {


    //同时设置，起作用的是 concurrency
    //@JmsListener(destination = "${ibm.mq.queueReceive}", concurrency = "2-3", containerFactory = "jmsListenerContainerFactorys")//)
    //@JmsListener(destination = "${ibm.mq.queueReceive}",  containerFactory = "jmsListenerContainerFactorys")//)
    @JmsListener(destination = "${ibm.mq.queueReceive}", concurrency = "20-30" )
    public void receiveMessage(Message data) throws JMSException {
        log.info("接受到消息[{}]", SysUtils.getString(data));
        ThreadUtil.sleep(5, TimeUnit.SECONDS);
        log.info("处理完毕");
    }

    public void receiveMessages(Message data) {
        log.info("接受到消息[{}]", data);
        ThreadUtil.sleep(15, TimeUnit.SECONDS);
        log.info("处理完毕");
    }

    //@JmsListener(destination = "DEV.QUEUE.1")
    public void receiveMessageDTO(Object data) {
        log.info("接受到消息[{}]", data);
    }

}
